package com.xzh.controller;

import com.github.pagehelper.PageInfo;
import com.xzh.common.Result;
import com.xzh.entity.CarInformation;
import com.xzh.service.CarInService;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Home/CarInformation")
public class CarInController {

    @Resource
    private CarInService carInService;

    //页数选择和用户数据查询
    @GetMapping("/selectPage")
    public Result selectPage(
            CarInformation e,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize) {
        PageInfo<CarInformation> pageInfo = carInService.selectPage(e,pageNum, pageSize);
        return Result.success(pageInfo);
    }

    //小窗口展示发布人信息查询
    @GetMapping("/hhh")
    public Result getCarInformation(@RequestParam int userId) {
        CarInformation hh = carInService.getCarInformation(userId);
        return Result.success(hh);
    }

    //发布拼车
    @PostMapping("/add")
    public Result add(@RequestBody CarInformation e) {
        carInService.add(e);
        return Result.success();
    }

    //更新拼车订单status
    @Transactional
    @PutMapping("")
    public Result updateOrderStatus(@RequestBody CarInformation e) {
        carInService.updateOrderStatus(e);
        return Result.success();
    }

}
